#!/usr/bin/env bash
# 网络工具子菜单

network_menu_show() {
  clear
  echo -e "${YELLOW}【网络工具】${RESET}"
  echo -e "  ${GREEN}1.${RESET} 查看本机公网 IP"
  echo -e "  ${GREEN}2.${RESET} Ping 测试"
  echo -e "  ${GREEN}3.${RESET} Traceroute 路由追踪"
  echo -e "  ${GREEN}4.${RESET} Curl 测试网页连通性"
  echo -e "  ${GREEN}5.${RESET} 检测 IP 质量 (IP.Check.Place)"
  echo -e "  ${GREEN}6.${RESET} 配置防火墙 UFW"
  echo ""
  echo -e "  ${GREEN}0.${RESET} 返回主菜单"
}

network_menu_loop() {
  while true; do
    network_menu_show
    read -rp "请选择 [0-6]: " a
    case "$a" in
      1) pick "查看本机公网 IP";           run_or_stub show_public_ip ;;
      2) pick "Ping 测试";                 run_or_stub ping_test_interactive ;;
      3) pick "Traceroute 路由追踪";       run_or_stub traceroute_test_interactive ;;
      4) pick "Curl 测试网页连通性";       run_or_stub curl_head_test_interactive ;;
      5) pick "检测 IP 质量 (IP.Check.Place)"; run_or_stub check_ip_quality ;;
      6) pick "配置防火墙 UFW";            run_or_stub ufw_menu ;;
      0) break ;;
      *) echo -e "${RED}${BOLD}❌ 无效输入，请重试${RESET}" ;;
    esac
    [[ "$a" != 0 ]] && read -rp "按回车键返回上级..."
  done
}
